package com.zycfc.zsf.boot.web.util;

import java.util.*;
import com.zycfc.zsf.boot.logback.core.*;
import com.zycfc.zsf.boot.redis.*;
import java.util.regex.*;
import com.zycfc.zsf.boot.util.json.*;
import java.nio.charset.*;
import org.slf4j.*;

public class CheckRespCodeUtil
{
    private static final Logger log;
    private static final String RESP_CODE_PATTERN = "^[0-9A]{1}[0-9]{6}$";
    private static final String INVALID_CODE_VAL = "9999999";
    private static final String INVALID_CODE_MSG = "\u8fd4\u56de\u7684\u539f\u54cd\u5e94\u7801[?]\u4e0d\u7b26\u5408\u89c4\u5219";
    private static final String QUESTION_MARK_SYMBOL = "?";
    private static final String RESP_CODE_KEY = "code";
    private static final String RESP_MSG_KEY = "message";
    private static final String REPORtED_RESP_CODE_KEY = "zsf:reportedRespCode";
    
    public static byte[] checkRespCode(final Map<String, Object> responseMap, final ApiTranInf apiTranInf, final IRedisOperater redisOperater) {
        final String oriCode = apiTranInf.getRespCode();
        final boolean isCodeValid = Pattern.matches("^[0-9A]{1}[0-9]{6}$", oriCode);
        if (isCodeValid) {
            return null;
        }
        final Map<String, String> reportedCodeMap = (Map<String, String>)redisOperater.hgetAll("zsf:reportedRespCode", true);
        CheckRespCodeUtil.log.info("\u672c\u6b21\u54cd\u5e94\u7801:{}\u4e0d\u7b26\u5408\u89c4\u8303-\u5df2\u62a5\u5907\u54cd\u5e94\u7801:{}", (Object)oriCode, (Object)((reportedCodeMap != null) ? JsonUtils.objectToJson((Object)reportedCodeMap) : null));
        if (reportedCodeMap != null && reportedCodeMap.containsKey(oriCode)) {
            CheckRespCodeUtil.log.info("\u672c\u6b21\u54cd\u5e94\u7801:{}\u4e0d\u7b26\u5408\u89c4\u8303,\u4f46\u5728\u62a5\u5907\u5217\u8868\u4e2d", (Object)oriCode);
            return null;
        }
        final String newMessage = "\u8fd4\u56de\u7684\u539f\u54cd\u5e94\u7801[?]\u4e0d\u7b26\u5408\u89c4\u5219".replace("?", oriCode);
        CheckRespCodeUtil.log.info("\u672c\u6b21\u54cd\u5e94\u7801:{}\u4e0d\u7b26\u5408\u89c4\u8303\uff0c\u4e5f\u672a\u5728\u62a5\u5907\u5217\u8868\u4e2d\uff0c\u51c6\u5907\u66ff\u6362\u6210\u9ed8\u8ba4\u54cd\u5e94\u7801:999999\uff0c\u54cd\u5e94\u63cf\u8ff0\u66ff\u6362\u4e3a:{}", (Object)oriCode, (Object)newMessage);
        apiTranInf.setRespCode("9999999");
        apiTranInf.setRespMsg(newMessage);
        responseMap.put("code", "9999999");
        responseMap.put("message", newMessage);
        final String newRespContent = JsonUtils.objectToJson((Object)responseMap);
        return newRespContent.getBytes(StandardCharsets.UTF_8);
    }
    
    static {
        log = LoggerFactory.getLogger((Class)CheckRespCodeUtil.class);
    }
}
